class TextUtils {
  // 单行文本截断
  static truncateSingleLine(element) {
    element.style.whiteSpace = "nowrap";
    element.style.textOverflow = "ellipsis";
  }

  // 多行文本截断
  static truncateMultiLine(element, maxLines) {
    const lineHeight = parseFloat(getComputedStyle(element).lineHeight);
    const maxHeight = maxLines * lineHeight;

    if (element.scrollHeight > maxHeight) {
      element.style.overflow = "hidden";
      element.style.textOverflow = "ellipsis";
      element.style.whiteSpace = "pre-line";
      element.style.display = "-webkit-box";
      element.style.webkitLineClamp = maxLines;
      element.style.webkitBoxOrient = "vertical";
    }
  }
}

export default TextUtils;
